package com.ai.enviro.utils;

import org.springframework.lang.Nullable;

import java.util.List;

public class StringUtils {
    public static final String EMPTY = "";

    public static boolean isEmpty(@Nullable String str) {
        return str == null || "".equals(str);
    }

    public static boolean isNotEmpty(@Nullable String str) {
        return !isEmpty(str);
    }

    public static boolean endWithAnyIgnoreCase(String str, List<String> suffix) {
        if (isEmpty(str) || CollectionUtils.isEmpty(suffix)) {
            return false;
        }
        str = str.toUpperCase();
        for (String s : suffix) {
            if (str.endsWith(s.toUpperCase())) {
                return true;
            }
        }
        return false;
    }

    public static String limitEnd(String s, int len) {
        if (s == null || s.length() <= len) {
            return s;
        }
        return s.substring(s.length() - len);
    }

    public static String build(String... strings) {
        StringBuilder builder = new StringBuilder();
        for (String string : strings) {
            builder.append(string);
        }
        return builder.toString();
    }

    public static boolean containsAny(String content, List<String> subStrings) {
        if (content == null || CollectionUtils.isEmpty(subStrings)) {
            return false;
        }
        for (String subString : subStrings) {
            if (content.contains(subString)) {
                return true;
            }
        }
        return false;
    }
}
